package com.cyx.demo1_zhs.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cyx.demo1_zhs.info.EmpInfo;
import com.cyx.demo1_zhs.mapper.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements IEmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public int add(EmpInfo empInfo) {
        return empMapper.insert(empInfo);
    }

    @Override
    public int update(EmpInfo empInfo) {
        LambdaUpdateWrapper<EmpInfo> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.eq(EmpInfo::getId, empInfo.getId());
        queryWrapper.set(EmpInfo::getAge, empInfo.getAge());
        return empMapper.update(queryWrapper);
    }

    @Override
    public int delete(Integer id) {
        return empMapper.deleteById(id);
    }

    @Override
    public List<EmpInfo> list() {
        return empMapper.selectList(new LambdaQueryWrapper<>());
    }
}
